package cst.a720yyq.zyfypt_720yyq.View.Fragment.VideoFragment;


import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cst.a720yyq.zyfypt_720yyq.Adapter.SVideoAdapter;
import cst.a720yyq.zyfypt_720yyq.Bean.SVideoBean;
import cst.a720yyq.zyfypt_720yyq.Interface.ToudouListener;
import cst.a720yyq.zyfypt_720yyq.Modle.ResModle;
import cst.a720yyq.zyfypt_720yyq.R;
import cst.a720yyq.zyfypt_720yyq.View.toasty.Toasty;


/**
 * A simple {@link Fragment} subclass.
 */
public class SVideoFragment extends Fragment {

    private RecyclerView recyclerView;
    private SVideoAdapter adapter;
    private List<SVideoBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private ToudouListener<List<SVideoBean>> listener;
    private ResModle model;
    private ProgressDialog dialog;
    private SharedPreferences sp;

    public SVideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_zhuan_video, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.svid_rec);
        adapter = new SVideoAdapter(getActivity());
        list = new ArrayList<SVideoBean>();
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        dialog = new ProgressDialog(getActivity());
        dialog.setTitle(R.string.t_JV_loading);

        listener = new ToudouListener<List<SVideoBean>>() {

            @Override
            public void onResponce(List<SVideoBean> l) {
                dialog.dismiss();
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {
                dialog.dismiss();
                Toasty.error(getActivity(),"网络连接错误，请检查网络是否连通", Toast.LENGTH_SHORT).show();
            }
        };
        sp = getActivity().getSharedPreferences("ME", Context.MODE_PRIVATE);
        dialog.show();
        model=new ResModle("gson",sp.getString("session_id",""));
        model.getList("svideo",1,listener);
        // Inflate the layout for this fragment
        return view;
    }

}
